/*
*************************************
* PocketGTT
*************************************
This file is part of PocketGTT.

PocketGTT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PocketGTT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PocketGTT.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "gtt_stop.h"
#include <QDebug>

GTT_Stop::GTT_Stop(QObject *parent) :
    QObject(parent)
{
    hiddenEmpty = true;
    hiddenPositionKnown = false;
}


void GTT_Stop::SvuotaFermata()
{
    // clean general stop & lines informations
    hiddenFermataNumero.clear();
    hiddenFermataNome.clear();
    hiddenFermataIndirizzo.clear();
    hiddenLinee.clear();

    // clean stop location informations
    // removed next two lines due to heavy network call
    //    hiddenFermataLat = 0;
    //    hiddenFermataLng = 0;

    hiddenPositionKnown = false;

    // set propriety Empty
    hiddenEmpty = true;

    emit GTTon_fermata_updated();
}

void GTT_Stop::LoadComplete()
{
    hiddenEmpty = false;
    emit GTTon_fermata_updated();
#if ATTIVADEBUG
    qDebug() << "emesso load complete";
#endif
}

bool GTT_Stop::isEmpty() { return hiddenEmpty; }

////////////////////////////////////////////////////////////
// PROPERTIES for stop general info functions
////////////////////////////////////////////////////////////
QString GTT_Stop::getFermataNumero() { return hiddenFermataNumero; }
void GTT_Stop::setFermataNumero(const QString& stop)
{
    hiddenFermataNumero = stop;
}

const QString GTT_Stop::getFermataNome() { return hiddenFermataNome; }
void GTT_Stop::setFermataNome(const QString &name)
{
    hiddenFermataNome = name;
}

const QString GTT_Stop::getFermataIndirizzo() { return hiddenFermataIndirizzo; }
void GTT_Stop::setFermataIndirizzo(const QString &street)
{
    hiddenFermataIndirizzo = street;
}

////////////////////////////////////////////////////////////
// PROPERTIES for stop lines info functions
////////////////////////////////////////////////////////////
QList<GTT_Line *> GTT_Stop::getLinee()
{
    return hiddenLinee;
}
void GTT_Stop::addLinea(GTT_Line *line)
{
    hiddenLinee.append(line);
}
void GTT_Stop::printLinee()
{
#if ATTIVADEBUG
    qDebug() << " print linee " << hiddenLinee.count();
#endif

    for (int i=0; i < hiddenLinee.count(); ++i) {
        hiddenLinee.at(i)->printLinea();
    }
}
int GTT_Stop::getLineeCount()
{
    return hiddenLinee.size();
}
QString GTT_Stop::getLineaNumeroByIndex(const int id)
{
    if (id >= 0 && id <hiddenLinee.size()) {
        return hiddenLinee.at(id)->getLineaNumero();
    }
    else {
        return "";
    }
}
QString GTT_Stop::getLineaOrarioByIndex(const int idL, const int id)
{

    QStringList temp_strList;
    if (idL <hiddenLinee.size()  && id >= 0) {
        temp_strList = hiddenLinee.at(idL)->getOrario();
        return temp_strList.at(id);
        //        return hiddenLinee.at(idL)->getOrario();
    }
    else {
        temp_strList.append("00:00");
        return temp_strList.at(0);
    }
}

QList<int> GTT_Stop::getLineaOrarioByIndexNum()//const int id)
{
    QList<int> temp_intList;
    int i=0;
    while (i < hiddenLinee.size()) {
        temp_intList.append( hiddenLinee.at(i)->getOrario().count());
        i++;
    }
    return temp_intList;
}

bool GTT_Stop::getLineaRealTimeByIndex(const int idL, const int idT)
{
    if (idL >= 0 && idL < hiddenLinee.size()) {
        QList<bool> localBool = hiddenLinee.at(idL)->getRealTime();
        if (idT >= 0 && idT < localBool.size()) {
            return localBool.at(idT);
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}

////////////////////////////////////////////////////////////
// PROPERTIES for location info functions
////////////////////////////////////////////////////////////
bool GTT_Stop::isPositionKnown() { return hiddenPositionKnown; }
void GTT_Stop::setPositionKnown(bool pos_ok)
{
    hiddenPositionKnown = pos_ok;
    emit GTTon_fermata_pos_updated();
}

double GTT_Stop::getFermataLat() { return hiddenFermataLat; }
void GTT_Stop::setFermataLat(const double lat)
{
    hiddenFermataLat = lat;
    emit GTTon_fermata_pos_updated();
}

double GTT_Stop::getFermataLng() { return hiddenFermataLng; }
void GTT_Stop::setFermataLng(const double lng)
{
    hiddenFermataLng = lng;
    emit GTTon_fermata_pos_updated();
}
